package sz.szsmk.citizencard.mvp.presenter;

import com.google.gson.Gson;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.PrepayWebRequest;
import sz.szsmk.citizencard.model.network.bean.response.PrepayResponse;
import sz.szsmk.citizencard.mvp.contract.IAllTypeContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.util.Constant;

import javax.inject.Inject;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/7/12 11:30
 * description:
 */
public class AllTypePresenter extends IBasePresenter
        implements IAllTypeContact.IAllTypePresenter<IAllTypeContact.IAllTypeView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;
    @Inject
    public AllTypePresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }


    @Override
    public void getUserInfo() {

    }

    @Override
    public void prepayWebsiteList() {
        PrepayWebRequest prepayWebRequest = new PrepayWebRequest();
        prepayWebRequest.setLatitude("117.11811");
        prepayWebRequest.setLongitude("60.1181");
        prepayWebRequest.setPage_num("1");
        prepayWebRequest.setPage_size("3");
        String json = new Gson().toJson(prepayWebRequest);
        L.e(Constant.TAG, json);
        mNetworkDateSource.prepayWebsiteList(prepayWebRequest, new SubscribeResult<PrepayResponse>() {
            @Override
            protected void onOk(PrepayResponse response) {
                if (response == null){
                    return;
                }

                String json = new Gson().toJson(response);
                L.e(Constant.TAG, "prepayWebsiteList响应:" + json);
                ((IAllTypeContact.IAllTypeView) mView).prepaySuccess(response);
            }

            @Override
            protected void onFailure(PrepayResponse response) {
                super.onFailure(response);
                ((IAllTypeContact.IAllTypeView) mView).prepayFaile(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });

    }

    @Override
    public void websiteInfo() {

    }

}
